package com.cn.mobileproject.view.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.mobileproject.bean.User;

public class TaskUserAdapter extends BaseAdapter{
	
	
	List<User> mList;
	protected Context mContext;

	public TaskUserAdapter(Context context){
		mContext = context;
	}
	
	public void setList(List<User> list){
		if(mList==null){
			mList = new ArrayList<User>();
		}
		else{
			mList.clear();
		}
		if(list!=null)mList.addAll(list);
	}
	
	@Override
	public int getCount() {
		if(mList==null) return 0;
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	public void addUser(User user){
		if(user==null) return;
		if(mList==null){
			mList = new ArrayList<User>();
		}
		mList.add(user);
	}
	
	public void removeUser(User user){
		if(user==null) return;
		if(mList==null){
			return;
		}
		mList.remove(user);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView text = new TextView(mContext);
		User user = mList.get(position);
		text.setText(user.username);
		return text;
	}

}
